package cn.numeron.wxarticle.api.other

import androidx.room.Room
import cn.numeron.android.AppRuntime
import cn.numeron.wxarticle.api.wxarticle.WxArticleDatabase
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import retrofit2.Retrofit
import retrofit2.create

@Module
@InstallIn(SingletonComponent::class)
object WxArticleModule {

    @get:Provides
    val wxArticleDatabase: WxArticleDatabase by lazy(LazyThreadSafetyMode.SYNCHRONIZED) {
        Room.databaseBuilder(AppRuntime.context, WxArticleDatabase::class.java, "account.db")
            .fallbackToDestructiveMigration()
            .build()
    }

    @Provides
    fun wxArticleApi(retrofit: Retrofit): WxArticleApi = retrofit.create()

    @Provides
    fun wxArticleDao(database: WxArticleDatabase) = database.wxArticleDao

}
